package com.xnfh.home.adapter

import android.view.View
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.xnfh.framework.bean.CropTypeBean
import com.xnfh.framework.utils.getColorFromResource
import com.xnfh.home.R
import com.xnfh.home.databinding.ItemCropTypeSelectBinding

/**
 * @Description:
 * @Author: ziheng
 * @CreateDate: 2024/1/8 10:18
 * @UpdateUser: ziheng
 * @UpdateDate: 2024/1/8 10:18
 * @UpdateRemark: 更新说明
 */
class DiseaseTypeAdapter: BaseQuickAdapter<CropTypeBean,BaseDataBindingHolder<ItemCropTypeSelectBinding>>(R.layout.item_crop_type_select){
    private var currSelect : Int? = null
    override fun convert(holder: BaseDataBindingHolder<ItemCropTypeSelectBinding>, item: CropTypeBean) {
        val dataBinding = holder.dataBinding
        dataBinding?.itemDiseaseTypeName?.text = item.typeName
        if(item.isSelect){
            currSelect = holder.layoutPosition
            dataBinding?.itemDiseaseTypeName?.setTextColor(getColorFromResource(R.color.color_00C358))
            dataBinding?.itemDiseaseTypeSelectTips?.visibility = View.VISIBLE
        }else{
            dataBinding?.itemDiseaseTypeName?.setTextColor(getColorFromResource(R.color.black))
            dataBinding?.itemDiseaseTypeSelectTips?.visibility = View.GONE
        }
    }
    fun updateSelectItem(position: Int){
        if(currSelect == position) return
        if(currSelect != null){
            data[currSelect!!].isSelect = false
            notifyItemChanged(currSelect!!)
        }
        currSelect = position
        data[currSelect!!].isSelect = true
        notifyItemChanged(currSelect!!)
    }

    fun resetSelect(){
        if(currSelect == null) return
        data[currSelect!!].isSelect = false
        notifyItemChanged(currSelect!!)
    }
}